<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of residualresample</title>
  <meta name="keywords" content="residualresample">
  <meta name="description" content="RESIDUALRESAMPLE  Residual resampling for SIR. Performs the resampling stage of">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../menu.html">Home</a> &gt;  <a href="#">ReBEL-0.2.7</a> &gt; <a href="#">core</a> &gt; residualresample.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../menu.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="menu.html">Index for .\ReBEL-0.2.7\core&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>residualresample
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>RESIDUALRESAMPLE  Residual resampling for SIR. Performs the resampling stage of</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function outIndex = residualResample(inIndex, weights); </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> RESIDUALRESAMPLE  Residual resampling for SIR. Performs the resampling stage of
                   the SIR algorithm in order(number of samples) steps.

   outIndex = residualResample(inIndex, weights)

   INPUT
          inIndex        (r-vector) Input particle indices.
          weights        (r-vector) Normalised importance weights
   OUTPUT
          outIndex          Resampled indices.

   See also</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="gmsppf.html" class="code" title="function [estimate, ParticleFilterDS, pNoise, oNoise, extra] = gmsppf(ParticleFilterDS, pNoise, oNoise, obs, U1, U2, InferenceDS)">gmsppf</a>	GMSPPF  Gaussian Mixture Sigma-Point Particle Filter</li><li><a href="gspf.html" class="code" title="function [estimate, ParticleFilterDS, pNoise, oNoise] = gspf(ParticleFilterDS, pNoise, oNoise, obs, U1, U2, InferenceDS)">gspf</a>	GSPF  Gaussian Sum Particle Filter</li><li><a href="pf.html" class="code" title="function [estimate, ParticleFilterDS, pNoise, oNoise] = pf(ParticleFilterDS, pNoise, oNoise, obs, U1, U2, InferenceDS)">pf</a>	PF  Generic Particle Filter</li><li><a href="sppf.html" class="code" title="function [estimate, ParticleFilterDS, pNoise, oNoise] = sppf(ParticleFilterDS, pNoise, oNoise, obs, U1, U2, InferenceDS)">sppf</a>	SPPF  Sigma-Point Particle Filter.</li></ul>
<!-- crossreference -->


<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function outIndex = residualResample(inIndex, weights);</a>
0002 
0003 <span class="comment">% RESIDUALRESAMPLE  Residual resampling for SIR. Performs the resampling stage of</span>
0004 <span class="comment">%                   the SIR algorithm in order(number of samples) steps.</span>
0005 <span class="comment">%</span>
0006 <span class="comment">%   outIndex = residualResample(inIndex, weights)</span>
0007 <span class="comment">%</span>
0008 <span class="comment">%   INPUT</span>
0009 <span class="comment">%          inIndex        (r-vector) Input particle indices.</span>
0010 <span class="comment">%          weights        (r-vector) Normalised importance weights</span>
0011 <span class="comment">%   OUTPUT</span>
0012 <span class="comment">%          outIndex          Resampled indices.</span>
0013 <span class="comment">%</span>
0014 <span class="comment">%   See also</span>
0015 <span class="comment">%</span>
0016 
0017 <span class="comment">%   Copyright  (c) Arnaud Doucet, Nando de Freitas and Rudolph van der Merwe (1998-2002)</span>
0018 
0019 <span class="comment">%   This file is part of the ReBEL Toolkit. The ReBEL Toolkit is available free for</span>
0020 <span class="comment">%   academic use only (see included license file) and can be obtained from</span>
0021 <span class="comment">%   http://choosh.csee.ogi.edu/rebel/.  Businesses wishing to obtain a copy of the</span>
0022 <span class="comment">%   software should contact rebel@csee.ogi.edu for commercial licensing information.</span>
0023 <span class="comment">%</span>
0024 <span class="comment">%   See LICENSE (which should be part of the main toolkit distribution) for more</span>
0025 <span class="comment">%   detail.</span>
0026 
0027 <span class="comment">%=============================================================================================</span>
0028 
0029 <span class="keyword">if</span> (nargin ~= 2),
0030     error(<span class="string">' [ residualResample ] Not enough input arguments.'</span>);
0031 <span class="keyword">end</span>
0032 
0033 S = length(weights);       <span class="comment">% S = Number of particles.</span>
0034 
0035 outIndex = zeros(1,S);   <span class="comment">% setup output index buffer</span>
0036 
0037 <span class="comment">%=== RESIDUAL RESAMPLING  ==========================================================</span>
0038 
0039 N_kind= zeros(1,S);
0040 
0041 <span class="comment">% first integer part</span>
0042 weights_res = S*weights;
0043 N_kind = fix(weights_res);
0044 
0045 <span class="comment">% residual number of particles to sample</span>
0046 N_res = S-sum(N_kind);
0047 
0048 <span class="keyword">if</span> N_res
0049 
0050     weights_res = (weights_res-N_kind)/N_res;
0051     cumDist = cumsum(weights_res);
0052 
0053     <span class="comment">% generate N_res ordered random variables uniformly distributed in [0,1]</span>
0054     u = fliplr(cumprod(rand(1,N_res).^(1./(N_res:-1:1))));
0055     j=1;
0056     <span class="keyword">for</span> i=1:N_res
0057         <span class="keyword">while</span> (u(1,i)&gt;cumDist(1,j))
0058             j=j+1;
0059         <span class="keyword">end</span>
0060         N_kind(1,j)=N_kind(1,j)+1;
0061     <span class="keyword">end</span>;
0062 
0063 <span class="keyword">end</span>;
0064 
0065 
0066 <span class="comment">%=== COPY RESAMPLED TRAJECTORIES =====================================================</span>
0067 
0068 index=1;
0069 <span class="keyword">for</span> i=1:S
0070     <span class="keyword">if</span> (N_kind(1,i)&gt;0)
0071         <span class="keyword">for</span> j=index:index+N_kind(1,i)-1
0072             outIndex(j) = inIndex(i);
0073         <span class="keyword">end</span>;
0074     <span class="keyword">end</span>;
0075     index = index+N_kind(1,i);
0076 <span class="keyword">end</span>
0077 
0078 
0079 <span class="comment">%----------------------------------------------------------------------------------------</span>
0080 
0081 
0082 
0083 
0084 
0085 
0086 
0087</pre></div>
<hr><address>Generated on Tue 26-Sep-2006 10:36:21 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>